﻿package
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent;
	import flash.geom.ColorTransform;
	import fl.motion.Color;
	import flash.filters.GlowFilter;
	
	public class BtnRoll_BgGlow
	{
		//VARIABLES INTERNAS SETEABLES OBLIGATORIAS.
			
			public var clip:MovieClip;
		
		//VARIABLES INTERNAS SETEABLES OPCIONALES.
			
			public var useHand:Boolean = true;
			public var easeType:Function = Regular.easeOut;
			public var easeTime:Number = 0.25;
			public var initColor:uint = 0xFFFFFF;
			public var finalColor:uint = 0x000000;
			public var glowColor:uint = 0xFFFFFF;
			public var topAlpha:Number = 1;
			public var blur:uint = 10;
			
		//VARIABLES INTERNAS.
		
			//private var BgGlowTimer:Timer;
			private var alphaTween:Tween;
			private var colorInfo:ColorTransform;
		
		//CONSTRUCTOR.
		public function BtnRoll_BgGlow()
		{
		
		}
		
		//INIT.
		public function init()
		{
			//SETEA LA MANITO.
			clip.hit.buttonMode = useHand;
			clip.hit.useHandCursor = useHand;
			
			//EXTRAE LA DATA DE COLOR.
			colorInfo = clip.subClip.lbl.transform.colorTransform;
			
			//APLICA EL FILTRO.
			var glow:GlowFilter = new GlowFilter(glowColor, 1, blur, blur, 2, 3, false, false);
			clip.subClip.bg.filters = [glow];
			
			//ACTIVA EL ROLL OVER Y ROLL OUT DEL CLIP.
			clip.hit.addEventListener(MouseEvent.MOUSE_OVER, rollOverHandler);
			clip.hit.addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler);
		}
		
		//MOUSE HANDLERS.
		private function rollOverHandler(event:MouseEvent):void
		{
			//
			alphaTween = new Tween(clip.subClip.bg, "alpha", easeType, clip.subClip.bg.alpha, topAlpha, easeTime, true);
			alphaTween.addEventListener(TweenEvent.MOTION_CHANGE, setTint);
		}
		private function rollOutHandler(event:MouseEvent):void
		{
			///
			alphaTween = new Tween(clip.subClip.bg, "alpha", easeType, clip.subClip.bg.alpha, 0, easeTime, true);
			alphaTween.addEventListener(TweenEvent.MOTION_CHANGE, setTint);
		}
		
		//SETEA EL TINT.
		function setTint(event:TweenEvent):void
		{
			colorInfo.color = Color.interpolateColor(initColor, finalColor, event.position);
			clip.subClip.lbl.transform.colorTransform = colorInfo;
		}
	}
}